package com.netstar;

import android.content.Context;
import android.content.SharedPreferences;

public class AppPreferences {
	public static AppPreferences getInstance(Context context) {
		if (null == sPreferences) {
			sPreferences = new AppPreferences(context);
		}
		return sPreferences;
	}

	private static AppPreferences sPreferences;

	private SharedPreferences mSharedPreferences;

	private AppPreferences(Context context) {
		mSharedPreferences = context.getSharedPreferences("prefs",
				Context.MODE_PRIVATE);
	}

	private static String KEY_NET_SPEED = "speed";

	/**
	 * In Kbps, default to 0.
	 */
	public float getLastNetSpeed() {
		return mSharedPreferences.getFloat(KEY_NET_SPEED, 0.0f);
	}

	public void setLastNetSpeed(float f) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putFloat(KEY_NET_SPEED, f);
		editor.commit();
	}

	public long getBootTime() {
		return mSharedPreferences.getLong("last_boot", 0);
	}

	public void setBootTime(long boot) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putLong("last_boot", boot);
		editor.commit();
	}

	public long getLastSyncTime() {
		return mSharedPreferences.getLong("last_sync", 0);
	}

	public void setLastSyncTime(long time) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putLong("last_sync", time);
		editor.commit();
	}

	public void setProvincePos(int pos) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putInt("province_pos", pos);
		editor.commit();
	}

	public int getProvincePos() {
		return mSharedPreferences.getInt("province_pos", 0);
	}

	public void setChannelPos(int pos) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putInt("channel_pos", pos);
		editor.commit();
	}

	public int getChannelPos() {
		return mSharedPreferences.getInt("channel_pos", 0);
	}

	public void setMealPos(int pos) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putInt("meal_pos", pos);
		editor.commit();
	}

	public int getMealPos() {
		return mSharedPreferences.getInt("meal_pos", 0);
	}

	public boolean isLogin() {
		return mSharedPreferences.getBoolean("loggedIn", false);
	}

	public void setLogin(boolean isLogin) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putBoolean("loggedIn", isLogin);
		editor.commit();
	}

	public String getLoggedInPhone() {
		return mSharedPreferences.getString("logged_phone", "");
	}

	public void setLoggedInPhone(String phone) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putString("logged_phone", null != phone ? phone : "");
		editor.commit();
	}

	public int getSortItemPositionIn2() {
		return mSharedPreferences.getInt("sort_pos_2", 0);
	}

	public void setSortItemPositionIn2(int pos) {
		SharedPreferences.Editor editor = mSharedPreferences.edit();
		editor.putInt("sort_pos_2", pos);
		editor.commit();
	}
}
